﻿using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;
using Modelica.Annotations;
using Modelica.ModelicaTypes;
using System.Windows.Data;
using System.Globalization;
using System;
using System.Windows.Controls;

namespace DrawTools
{    
    [ValueConversion(typeof(object), typeof(byte))]
    public class TabItemToList : IValueConverter {
        public object Convert(object value, Type typeTarget, object param, CultureInfo culture) {
            if (value == null) {
                return Binding.DoNothing;
            }
            TabItem t = value as TabItem;
            IconEditor i = t.Content as IconEditor;
            return i.Mclass.Icon.Graphics;
        }
        public object ConvertBack(object value, Type typeTarget, object param, CultureInfo culture) {
            throw new Exception("Not implementet conversion.");
        }
    }

    static class Annotations
    {
        //public static void ShowAnnotation(DrawingCanvas dc, Icon i)
        //{            
        //    HelperFunctions.DeleteAll(dc);

        //    foreach (GraphicItem gi in i.Members)
        //    {
        //        dc.Push(GraphicsBase.GetGraphicsByAnnotation(gi));     
        //    }
        //}


        public static void InitializeIcons(ModelicaClass[] mclass) {

            #region first Icon
            Icon[] icons = new Icon[3];

            icons[0] = new Icon();
            //{-100.0,-100.0,100.0,100.0,{
            icons[0].CoordinateSystem = new CoordinateSystem(new Extent(-100.0, -100.0, 100.0, 100.0));

            //Ellipse(true,{0,0,0},{255,127,127},LinePattern.Solid,FillPattern.Solid,0.25,{{-25.94,-24.44},{25.89,-3.273}}),
            Ellipse el1 = new Ellipse(
                Colors.Black,
                Color.FromRgb(255, 127, 127),
                LinePattern.Solid,
                FillPattern.None,
                0.25,
                new Extent(-25.94, -24.44, 25.89, -3.273));

            //Ellipse(true,{0,0,0},{255,127,127},LinePattern.Solid,FillPattern.Solid,0.25,{{-34.54,-10.05},{35.37,20.6}}),
            Ellipse el2 = new Ellipse(
                Colors.Black,
                Color.FromRgb(255, 127, 127),
                LinePattern.Solid,
                FillPattern.None,
                0.25,
                new Extent(-34.54, -10.05, 35.37, 20.6));

            ////Ellipse(true,{0,0,0},{255,127,127},LinePattern.Solid,FillPattern.Solid,0.25,{{-49.95,8.29},{50.05,49.12}}),
            Ellipse el3 = new Ellipse(
               Colors.Black,
               Color.FromRgb(255, 127, 127),
               LinePattern.Solid,
               FillPattern.None,
               0.25,
               new Extent(-49.95, 8.29, 50.05, 49.12));

            //Text(true,{0,0,255},{0,0,255},LinePattern.Solid,FillPattern.Solid,0.25,{{-99.71,-65.65},{100.2,-25.6}},"%name",0.0,"")}}
            Text tx1 = new Text(
                Color.FromRgb(0, 0, 255),
                Color.FromRgb(0, 0, 255),
                LinePattern.Solid,
                FillPattern.Solid,
                0.25,
                new Extent(-99.71, -65.65, 100.2, -25.6),
                "%name",
                12,
                "",
                new List<TextStyle>());

            icons[0].Graphics.Add(el1);
            icons[0].Graphics.Add(el2);
            icons[0].Graphics.Add(el3);
            icons[0].Graphics.Add(tx1);

            #endregion first Icon

            #region second Icon

            icons[1] = new Icon();
            //{-100.0,-100.0,100.0,100.0,{
            icons[1].CoordinateSystem = new CoordinateSystem(new Extent(-100.0, -100.0, 100.0, 100.0));

            //Ellipse(visible=true, fillColor={255,127,127}, fillPattern=FillPattern.Solid, extent={{56.05,-19.86},{106.9,0.8964}}),
            Ellipse el4 = new Ellipse(
                Colors.Black,
                Color.FromRgb(255, 127, 127),
                LinePattern.Solid,
                FillPattern.None,
                0.25,
                new Extent(56.05, -19.86, 106.9, 0.8964));

            //Ellipse(visible=true, fillColor={255,127,127}, fillPattern=FillPattern.Solid, extent={{-94.8,-15.43},{-24.89,15.22}}),
            Ellipse el5 = new Ellipse(
                Colors.Black,
                Color.FromRgb(255, 127, 127),
                LinePattern.Solid,
                FillPattern.None,
                0.25,
                new Extent(-94.8, -15.43, -24.89, 15.22));

            //Ellipse(visible=true, fillColor={255,127,127}, fillPattern=FillPattern.Solid, extent={{-35.55,-18.83},{64.45,22}}),
            Ellipse el6 = new Ellipse(
               Colors.Black,
               Color.FromRgb(255, 127, 127),
               LinePattern.Solid,
               FillPattern.None,
               0.25,
               new Extent(-35.55, -18.83, 64.45, 22));

            //Text(visible=true, lineColor={0,0,255}, fillColor={0,0,255}, fillPattern=FillPattern.Solid, extent={{-99.71,-84.51},{100.2,-44.46}},
            List<TextStyle> l = new List<TextStyle>();
            l.Add(TextStyle.Bold);

            Text tx2 = new Text(
                Color.FromRgb(0, 0, 255),
                Color.FromRgb(0, 0, 255),
                LinePattern.Solid,
                FillPattern.Solid,
                0.25,
                new Extent(-99.71, -84.51, 100.2, -44.46),
                "%name",
                12,
                "",
                l);

            icons[1].Graphics.Add(el4);
            icons[1].Graphics.Add(el5);
            icons[1].Graphics.Add(el6);
            icons[1].Graphics.Add(tx2);

            #endregion second icon

            #region third icon

            icons[2] = new Icon();
            //{-100.0,-100.0,100.0,100.0,{
            icons[2].CoordinateSystem = new CoordinateSystem(new Extent(-100.0, -100.0, 100.0, 100.0));

            //Line(true,{{-30.13,80.16},{-29.75,17.81}},{0,0,0},LinePattern.Solid,0.25,{Arrow.None,Arrow.None},3.0,false),            
            Line li1 = new Line(
                new Point[] { new Point(-30.13, 80.16), new Point(-29.75, 17.81) },
                Colors.Black,
                LinePattern.Solid,
                2,
                new Arrow[] { Arrow.None, Arrow.None },
                3.0,
                Smooth.None);

            //Rectangle(true,{0,0,0},{192,192,192},LinePattern.Solid,FillPattern.Solid,0.25,BorderPattern.None,{{-29.81,-47.62},{30.19,42.38}},0.0),
            Rectangle re1 = new Rectangle(
               Color.FromRgb(0, 0, 0),
               Color.FromRgb(192, 192, 192),
               LinePattern.Solid,
               FillPattern.Solid,
               0.25,
               BorderPattern.None,
               new Extent(-29.81, -47.62, 30.19, 42.38),
               0.0);

            //Line(true,{{30.14,22.13},{30.14,82.13}},{0,0,0},LinePattern.Solid,0.25,{Arrow.None,Arrow.None},3.0,false),
            Line li2 = new Line(
                new Point[] { new Point(30.14, 22.13), new Point(30.14, 82.13) },
                Colors.Black,
                LinePattern.Solid,
                2,
                new Arrow[] { Arrow.None, Arrow.None },
                3.0,
                Smooth.None);

            //Text(true,{0,0,0},{0,0,255},LinePattern.Solid,FillPattern.None,0.25,{{0.0,46.0},{0.0,106.0}},"%name",0.0,"")}}
            Text tx3 = new Text(
                Color.FromRgb(0, 0, 255),
                Color.FromRgb(0, 0, 255),
                LinePattern.Solid,
                FillPattern.Solid,
                0.25,
                new Extent(0.0, 46.0, 0.0, 106.0),
                "%name",
                12,
                "",
                new List<TextStyle>());

            icons[2].Graphics.Add(li1);
            icons[2].Graphics.Add(re1);
            icons[2].Graphics.Add(li2);
            icons[2].Graphics.Add(tx3);

            #endregion third icon

            mclass[0] = new ModelicaClass("Icon 1", new Diagram(), icons[0]);
            mclass[1] = new ModelicaClass("Icon 2", new Diagram(), icons[1]);
            mclass[2] = new ModelicaClass("Icon 3", new Diagram(), icons[2]);
        }
    }
}
